import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
export class Camera {
  constructor(aspect, renderer, cameraConf) {
    this.cameraConf = cameraConf
    this.renderer = renderer
    this.instance = new THREE.PerspectiveCamera(
      cameraConf.fov,
      aspect,
      cameraConf.near,
      cameraConf.far
    )
    this.OrbitControls = null
    // 相机的角度位置
    const { x1, y1, z1 } = cameraConf.position
    this.instance.position.set(x1, y1, z1)
    const { x3, y3, z3 } = cameraConf.up
    this.instance.up.x = x3
    this.instance.up.y = y3
    this.instance.up.z = z3
    this.addOrbitControls()
  }
  addOrbitControls() {
    const { x2, y2, z2 } = this.cameraConf.lookAt
    this.OrbitControls = new OrbitControls(this.instance, this.renderer.domElement)
    this.OrbitControls.target = new THREE.Vector3(x2, y2, z2)
    this.OrbitControls.maxAzimuthAngle = Math.PI
    // this.OrbitControls.update()
    // this.OrbitControls.minAzimuthAngle = Math.PI / 4
    this.OrbitControls.maxPolarAngle = Math.PI / 3
    // this.OrbitControls.minPolarAngle = Math.PI / 2
  }
}
